<script language="javascript">
$(function(){
	$('.active_toggle').jqTransform({imgPath:'jqforms/img/'});
	$("input[type='radio']").change(function() {
		if(this.checked) {
			$(this).parent().parent().addClass('active');
		}
		else {
			$(this).parent().parent().removeClass('active');
		}
	});
});
</script>

<div>
    <div class="main-title">
        <h2>
        	<span>Active Battles</span>
            <div class="active_toggle">
            	<form>
                    <div class="jqdrop_right">
                        <select id="votes" name="votes">
                            <option value="running">Running</option>
                            <option value="closed">Closed</option>
                            <option value="open">Open</option>
                        </select>
                    </div>
                    <p>
                        <input type="radio" id="" name="active_toggle" value="friends" >
                        <span class="at_label">Friends</span>
                    </p>
                    <p class="active">
                        <input type="radio" id="" name="active_toggle" value="all" checked >
                        <span class="at_label">All</span>
                    </p>
                    <br class="cleft" />
                </form>
            </div>
        </h2>
    </div>
    <div class="main-content">
        <ul class="battletabs">
        
			<!--Gets every challenge-->
            
			<?php
            include 'config/dbconfig.php';
			//read challenge
			$sqlquery=sprintf("SELECT * FROM challenges"); 

			$rs = mysql_query($sqlquery) or die(mysql_error());
			$totalRows = mysql_num_rows($rs);
			if ($totalRows > 0) {		
				
				while ($row= mysql_fetch_assoc($rs)) { 
				
				$challenge_id = $row['id'];
				$user_id = $row['challenge_user_id'];
				$title = $row['title'];
				//Gets the user who created the challenge's facebook id 
				
				$sqlquery=mysql_query("SELECT oauth_uid FROM users WHERE id = '$user_id'"); 			
				while($row_user = mysql_fetch_row($sqlquery)) {
				$user_facebook_id = $row_user[0];
				}
				
			?>
            <li>
                <div class="default">
                    <div class="btab_images">
                        <a href="javascript:void(0)"><img src="https://graph.facebook.com/<?php echo $user_facebook_id ?>/picture" class="wh40" /></a>
                    </div>
                    <div class="btab_details">
                        <div class="title">
                            <h3><span><?php echo $title; ?></span></h3><br />
                            <p class="sub">
							<?
							//read name
							#PEOPLE WHO ARE INVOVLED
							$sample_name_who_voted = "John Doe";
							?>
                                <span><?php echo $sample_name_who_voted; ?></span>
                            </p>
                        </div>
                    </div>
                    <div class="btab_join locked">
                        <p><a href="view_challenge.php?challenge_id=<?php echo $challenge_id ?>"><span>View</span></a></p>
                    </div>
					<?
						//read score
						#GET AVERAGE CHALLENGE RATING
						$sample_vote = "5 stars (test)"
						?>
                    <div style="float: right; margin-right: 10px; width: 125px;"><p><?php echo $sample_vote; ?></p></div>
                </div>
                <br class="cleft" />
            </li> 
			<?php
			}
			
			}
			?>        			
        </ul>
    </div>
</div>